﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace He.Web.user
{
    public partial class info_edit : System.Web.UI.Page
    {
        public He.Model.member Member = new Model.member();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
                return;
            }

            if (!IsPostBack)
            {
                He.BLL.member mgr = new He.BLL.member();
                string username = User.Identity.Name;
                if (mgr.Exists(username))
                {
                    this.Member = mgr.GetModel(username);
                    lblUserName.Text = Member.user_name;
                    lblEmail.Text = Member.email;
                    txtNikeName.Text = Member.nickname;
                    rblSex.SelectedValue = Member.sex;
                    txtBirthday.Text = Member.birthday;
                    txtTel.Text = Member.tel;
                    txtPhone.Text = Member.phone;
                    txtQQ.Text = Member.qq;
                    txtAddress.Text = Member.address;
                }
                else
                {
                    Response.Redirect("~/error.aspx?s=用户不存在");
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            He.BLL.member mgr = new He.BLL.member();
            string username = User.Identity.Name;
            if (mgr.Exists(username))
            {
                this.Member = mgr.GetModel(username);
                Member.nickname = txtNikeName.Text;
                Member.sex = rblSex.SelectedValue;
                Member.birthday = txtBirthday.Text;
                Member.tel = txtTel.Text;
                Member.phone = txtPhone.Text;
                Member.qq = txtQQ.Text;
                Member.address = txtAddress.Text;
                mgr.Update(Member);
                lblMsg.Text = "修改成功!";
            }
            else
            {
                Response.Redirect("~/error.aspx?s=用户不存在");
            }
        }
    }
}